package handler

import (
	"context"
	"user/internal/logic"
	"user/internal/repository"
	"user/pkg/e"
)

type UserService struct {
	logic.UnimplementedUserServiceServer
}

func NewUserService() *UserService {
	return &UserService{}
}

func (s *UserService) UserLogin(ctx context.Context, req *logic.UserRequest) (resp *logic.UserDetailResponse, err error) {
	var user repository.User
	resp = new(logic.UserDetailResponse)
	resp.Code = e.Success
	err = user.ShowUserInfo(req)
	if err != nil {
		resp.Code = e.Error
		return resp, err
	}
	resp.UserDetail = repository.BuildUser(user)
	return resp, nil
}

func (s *UserService) UserRegister(ctx context.Context, request *logic.UserRequest) (resp *logic.UserDetailResponse, err error) {
	var user repository.User
	resp = new(logic.UserDetailResponse)
	resp.Code = e.Success
	err = user.UserCreate(request)
	if err != nil {
		resp.Code = e.Error
		return resp, err
	}
	resp.UserDetail = repository.BuildUser(user)
	return resp, nil
}

func (s *UserService) UserLogout(ctx context.Context, request *logic.UserRequest) (*logic.UserDetailResponse, error) {
	//TODO implement me
	panic("implement me")
}
